﻿<%@ Page Language="C#" MasterPageFile="~/Demo.master" Inherits="DemoPage" Title="Show Case:User Login Sample (MSAJAX)" %>

<%@ Register Src="~/CodeFormatter.ascx" TagName="Code" TagPrefix="demo" %>
<asp:Content ID="Content1" ContentPlaceHolderID="DemoHolder" runat="Server">
    <div class="dna-state-info  ui-corner-all">
        In this sample i will show you how to using MSAjax's Authentication Service in User
        Login Form.It's not using PostBack then webservice.Click the Login Button blow to
        start the Demo.</div>
    <br />
    <DotNetAge:SimpleButton ID="LoingButton" runat="server" Text="Login" IconCssClass="ui-icon ui-icon-person" />
    <%--    <asp:HyperLink ID="LoingButton" runat="server" Style="cursor: pointer">Login</asp:HyperLink>
--%>
    <DotNetAge:Dialog ID="DemoDialog" runat="server" Draggable="true" Resizable="true"
        Title="User Login" ShowModal="true" OnClientOpen="resetLoginForm(this);" Position="Top">
        <Trigger TargetID="LoingButton" />
        <Buttons>
            <DotNetAge:DialogButton Text="Login" OnClientClick="userLogin(this);" />
            <DotNetAge:DialogButton Text="Cancel" OnClientClick="$(this).dialog('close')" />
        </Buttons>
        <BodyTemplate>
            <div class="dna-demo-fields">
                <div class="dna-state-error  ui-corner-all" id="loginInfo" style="display: none;
                    margin: 10px;">
                </div>
                <ul>
                    <li><span>User Name:</span>
                        <input id="userName" type="text" style="width: 200px" /></li>
                    <li><span>Password:</span>
                        <input type="password" id="passWord" style="width: 200px" /></li>
                    <li>
                        <input type="checkbox" id="cbAutoLogin" checked="checked" /><label for="cbAutoLogin">AutoLogin</label></li>
                </ul>
            </div>
        </BodyTemplate>
    </DotNetAge:Dialog>

    <script type="text/javascript">
        /// <reference name="MicrosoftAjax.js"/>
        function userLogin(el) {
            var _user = $get("userName");
            var _pwd = $get("passWord");
            var _auto = $get("cbAutoLogin");
            $("#" + el.id + " input").attr("disabled", "disabled");
            Sys.Services.AuthenticationService.login(_user.value, _pwd.value, _auto.checked, null, null, userLoginSuccessful, userLoginFailed, el);
        }

        function resetLoginForm(el) {
            $get("loginInfo").style.display = 'none';
            $get("loginInfo").innerHTML = "";
            $("#" + el.id + " input").attr("disabled", "");
            $get("userName").value = "";
            $get("passWord").value = "";
            $get("cbAutoLogin").value = "checked";
        }

        function userLoginSuccessful(validCredentials, userContext, methodName) {
            $("#" + userContext.id + " input").attr("disabled", "enabled");
            if (Sys.Services.AuthenticationService.get_isLoggedIn()) {
                alert("Login Success");
                $(userContext).dialog('close');
            }
            else {
                $get("loginInfo").style.display = 'block';
                $get("loginInfo").innerHTML = "Login Failed!";
            }

        }

        function userLoginFailed(error, userContext, methodName) {
            $("#" + userContext.id + " input").attr("disabled", "enabled");
            $get("loginInfo").style.display = 'block';
            $get("loginInfo").innerHTML = error.get_message();
        }
    </script>

    <br />
    <br />
    <br />
    <demo:Code runat="server" ID="codeView" SourceFile="~/Dialog/Codes/AjaxLoginSample.aspx" />
</asp:Content>
